package com.Pratice;

public class IsPossible {
	int[] pos;
	public static void main(String[] args) {
		int[] nums = new int[] {1,2,3,3,4};
		boolean res = new IsPossible().isPossible(nums);
		System.out.println(res);
	}

	public boolean isPossible(int[] nums) {
		boolean flag = false;
		pos = new int[nums.length];
		int start = 0,len = 0;
		for (int i = 0; i + 1 < nums.length; i++) {
			if(pos[i] == 1)
				continue;
			if(nums[i] == nums[i+1]) {
				if(!flag)
				{
					flag = true;
					start = i;
				}
				pos[i] = 1;
				len++;
				i++;
			}
			else {
				if(flag)
				{
					flag = false;
					if(len < 3)
					{
						return false;
					}
					i = start+1;
					len = 0;
				}
				len++;
			}
		}
		return false;
    }

}
